import 'package:asperm/tools/auth.dart';
import 'package:asperm/tools/const.dart';
import 'package:asperm/views/custom_cell.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../tools/tools.dart';
import '../views/myDialog.dart';


class MyPage extends StatefulWidget {
  const MyPage({super.key});

  @override
  State<MyPage> createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {

  String appVersion = '';

  @override
  void initState() {
    super.initState();
    getAppInfo();

  }

  getAppInfo() async {

    appVersion = await getAppVersionInfo();
    print('appVersion-----${appVersion}');


    setState(()  {
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Color(0xffF9F9F9),
        appBar: AppBar(
          centerTitle: true,
          title: Text(
            'My',
            style: TextStyle(fontSize: 18.sp,fontWeight: FontWeight.w600,color: Color(0xff1B1B1B),),
          ),
          backgroundColor: Colors.white,
          elevation: 0.0,
        ),
        body: Container(
          height: screenHeight(context),
          child: Container(
            width: double.infinity,
            color: Color(0xffF9F9F9),
            child: contentWidget(context),
          ),
        )
    );
  }

  contentWidget(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 20.h),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          CustomCell(
            rowHeight: 44.h,
            title: '版本',
            isHideArrows: true,
            subTitle: appVersion,
            hasNewVersion: false,
            clickAction: () {
              // JumpToAppStore();

            },
          ),

          Container(
            height: 48.h,
            width: 335.w,

            decoration: BoxDecoration(
              color: Color.fromRGBO(16, 37, 105, 1),
              borderRadius: BorderRadius.circular(5.h),
            ),
            margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.h,bottom: 40.h),
            child: TextButton(
              onPressed: () {
                if(isLogin()){
                  saveUsername('');
                }
                goLogin(context);

              },
              child: Text(
                isLogin() ? 'LOGOUT' : 'LOGIN',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w400,

                ),
              ),
            ),
          ),

        ],
      ),
    );
  }





}

